package algorithm.arrayAlgorithm;

/**
 * @ClassName: MaxSubArray
 * @Description 数组中的连续子数组的最大和
 * @Author skywingking
 * @Date 2022/1/3 1:45 下午
 **/
public class MaxSubArray {
    public int maxSubArray(int[] nums) {
        int ans = nums[0];
        int sum = 0;
        for (int num : nums) {
            if (sum > 0) {
                sum += num;
            } else {
                sum = num;
            }
            ans = Math.max(ans, sum);
        }
        return ans;
    }
}